import Dile_Methods from "@/utils/methods";
import { object_Inf } from "@/utils/typings/index.type";
import Utils_EquipState from "../utils-equipState";

/*
 * @Descripttion:模具状态工具类
 * @LastEditors: xzh
 * @LastEditTime: 2023-10-15 14:34:38
 */
export default class Utils_MoldState extends Utils_EquipState {
  /**
   * @Author: xzh
   * @Descripttion: 获取模具状态图表数据
   * @Param:
   * @param {Array} moldStateArr 模具状态数据源
   * @param {string} moldTotal 模具总数
   */
  static getMoldStateChart(moldStateArr: Array<object_Inf>, moldTotal: string) {
    return {
      option: {
        tooltip: {
          trigger: "item",
        },
        color: ["#506ABC", "#EE6666", "#FAC858", "#70BBD8", "#91CC75"],
        title: {
          text: moldTotal,
          subtext: "模具总数",
          left: "center",
          top: "center",
        },
        grid: {
          top: "3%",
          bottom: "28",
          left: "1%",
          right: "1%",
          containLabel: true,
        },
        legend: {
          bottom: 0,
          left: "center",
          data: moldStateArr.map((x: object_Inf) => x.moldState),
        },
        series: [
          {
            type: "pie",
            radius: ["40%", "70%"],
            label: {
              show: false,
            },
            data: moldStateArr.map(({ moldState, moldNum }: object_Inf) => ({
              name: moldState,
              value: moldNum,
            })),
          },
        ],
      },
      id: Dile_Methods.newGuid(),
    };
  }
  /**
   * @Author: xzh
   * @Descripttion: 获取模具故障图表
   * @Param:
   * @param {Array} moldStateArr
   */
  static getMoldFaultChart(moldStateArr: Array<object_Inf>) {
    return {
      option: {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        color: ["#ed7d31", "#4472c4"],
        legend: {
          bottom: 0,
        },
        grid: {
          top: "3%",
          bottom: "28",
          left: "1%",
          right: "1%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
        },
        yAxis: {
          type: "category",
          data: moldStateArr.map((x: object_Inf) => x.faultType),
        },
        series: [
          {
            field: "faultNum",
            title: this.t(
              "page.dashboardManageArr.afterSaleDashboardArr.equipStateArr.faultNum"
            ),
          },
          {
            field: "handleNum",
            title: this.t(
              "page.dashboardManageArr.afterSaleDashboardArr.equipStateArr.handleNum"
            ),
          },
        ].map(({ field, title }) => ({
          name: title,
          type: "bar",
          data: moldStateArr.map((x: object_Inf) => x[field]),
        })),
      },
      id: Dile_Methods.newGuid(),
    };
  }
}
